
	var rootPath = getRootPath();
$(document).ready(function(){
	
	var soshelpId = getQueryParamValue("soshelpId");
	var carOwnerUserId = getQueryParamValue("carOwnerUserId");
	$("#carOwnerUserId").val(carOwnerUserId);
	$("#soshelpId").val(soshelpId);
	
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/maintain/rescues/'+soshelpId,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			
			var wholeHtml = '';
			
			$.each(resultData,function(sosHelpIndex,sosHelpObj){
				
				$("#salesConsultantId").val(sosHelpObj.salesConsultantId);
				
				var sosHelpHtml = '';
				
				var supportDate = "";
				
				var createDate = "";
				
				if(sosHelpObj.supportDate == null){
					supportDate = " ";
				}else{
					supportDate = sosHelpObj.supportDate 
				}
				if(sosHelpObj.createDate == null){
					createDate = " ";
				}else{
					createDate = sosHelpObj.createDate 
				}
				
				if(sosHelpObj.status=="待救援"||sosHelpObj.status=="救援中"){
					
					sosHelpHtml = sosHelpHtml 	 + '<div class="panel panel-default">'
					  							 +   '<ul class="list-group">'
					  							 +     '<li class="list-group-item">'
					  							 +	     '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">请求时间：</span><span>'+ createDate +'</span>'
					  							 +		   '<span style="font-family:黑体;font-size:15px;color:#F6304F;float:right">'+ sosHelpObj.status +'</span>'
					  							 +		 '</p>'
					  							 +		 '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">救援时间：</span><span>'+ supportDate +'</span>'
					  							 +		 '</p>'
					  							 +		 '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">救援地址：</span><span>'+ sosHelpObj.helpLocal +'</span>'
					  							 +		 '</p>'
					  							 +	  '</li>'
					  							 +   '</ul>'
					  							 + '</div>'
					  							 + '<div class="panel panel-default">'
					  							 +   '<ul class="list-group">'
					  							 +     '<li class="list-group-item">'
					  							 +		 '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">救援电话：</span><span style="color:#42B4F7">'+ sosHelpObj.serviceHotline +'</span>'
					  							 +		 '</p>'
					  							 +		 '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">店&nbsp;&nbsp;&nbsp;&nbsp;名：</span><span>'+ sosHelpObj.dealerName +'</span>'
					  							 +		 '</p>'
					  							 +		 '<p>'
					  							 +		   '<span style="font-family:黑体;font-size:15px">地&nbsp;&nbsp;&nbsp;&nbsp;址：</span><span>'+ sosHelpObj.detailAddress +'</span>'
					  							 +		 '</p>'
					  							 +	   '</li>'
					  							 +	 '</ul>'
					  							 + '</div>'
						  						 + '<div class="panel panel-default">'
						  						 +   '<input style="background-color:#B8B8B8;color:white" type="button" data-toggle="modal" data-target="#myModal"  value="取消" class="btn btn-default btn-lg btn-block" />'
						  						 + '</div>'
				}
				else if(sosHelpObj.status=="已救援"){
					
					sosHelpHtml = sosHelpHtml 	 + '<div class="panel panel-default">'
												 +   '<ul class="list-group">'
												 +     '<li class="list-group-item">'
												 +	     '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">请求时间：</span><span>'+ createDate +'</span>'
												 +		   '<span style="font-family:黑体;font-size:15px;color:#48ACED;float:right">'+ sosHelpObj.status +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援时间：</span><span>'+ supportDate +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援地址：</span><span>'+ sosHelpObj.helpLocal +'</span>'
												 +		 '</p>'
												 +	  '</li>'
												 +   '</ul>'
												 + '</div>'
												 + '<div class="panel panel-default">'
												 +   '<ul class="list-group">'
												 +     '<li class="list-group-item">'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援电话：</span><span style="color:#42B4F7">'+ sosHelpObj.serviceHotline +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">店&nbsp;&nbsp;&nbsp;&nbsp;名：</span><span>'+ sosHelpObj.dealerName +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">地&nbsp;&nbsp;&nbsp;&nbsp;址：</span><span>'+ sosHelpObj.detailAddress +'</span>'
												 +		 '</p>'
												 +	   '</li>'
												 +	 '</ul>'
												 + '</div>'
				}
				else{
					
					sosHelpHtml = sosHelpHtml 	 + '<div class="panel panel-default">'
												 +   '<ul class="list-group">'
												 +     '<li class="list-group-item">'
												 +	     '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">请求时间：</span><span>'+ createDate +'</span>'
												 +		   '<span style="font-family:黑体;font-size:15px;color:#C0C0C0;float:right">'+ sosHelpObj.status +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援时间：</span><span>'+ supportDate +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援地址：</span><span>'+ sosHelpObj.helpLocal +'</span>'
												 +		 '</p>'
												 +	  '</li>'
												 +   '</ul>'
												 + '</div>'
												 + '<div class="panel panel-default">'
												 +   '<ul class="list-group">'
												 +     '<li class="list-group-item">'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">救援电话：</span><span style="color:#42B4F7">'+ sosHelpObj.serviceHotline +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">店&nbsp;&nbsp;&nbsp;&nbsp;名：</span><span>'+ sosHelpObj.dealerName +'</span>'
												 +		 '</p>'
												 +		 '<p>'
												 +		   '<span style="font-family:黑体;font-size:15px">地&nbsp;&nbsp;&nbsp;&nbsp;址：</span><span>'+ sosHelpObj.detailAddress +'</span>'
												 +		 '</p>'
												 +	   '</li>'
												 +	 '</ul>'
												 + '</div>'
				}

				
				wholeHtml += sosHelpHtml;
			});
			
			$("#information").append(wholeHtml);
		}
	});

	$('#modalSure').click(function(){
		var data={
		soshelpId:"",
		updateBy:"",
		status:"",
		salesConsultantId:"",
    }; 
    data.soshelpId = $.trim($("#soshelpId").val()); 
    data.updateBy = $.trim($("#carOwnerUserId").val()); 
    data.status = $.trim($("#status").val()); 
    data.salesConsultantId = $.trim($("#salesConsultantId").val()); 
    
    
	$.ajax({
		type : 'POST',
		url : rootPath+'/wechat/api/maintain/updateSosHelpStatus',
		contentType:"application/json",
		data: JSON.stringify(data),
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("失败");
		},
		success : function(data){
			$('#sosHelpModal').modal({
				keyboard: false,
				backdrop:false
			});
		}
	});
  });
})
function re(){
	window.location = rootPath + "/views/hp.html";
}
